<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /**
        * @param {number[]} nums
        * @param {number} k
        * @return {number}
        */
        var subarraySum = function (nums, k) {
            let count = 0
            let prefixSum = 0
            let sumMap = new Map()
            sumMap.set(0,1)
            for (let i=0;i<nums.length;i++){
                prefixSum+=nums[i]
                if (sumMap.has(prefixSum-k)){
                    count+=sumMap.get(prefixSum-k)
                }
                if (sumMap.has(prefixSum)){
                    sumMap.set(prefixSum,sumMap.get(prefixSum)+1)
                }else{
                    sumMap.set(prefixSum, 1)
                }
                
            }

            return count
        };
        console.log(subarraySum([-1,-1,1],0))
    </script>
</body>

</html>